package org.example.controller.sysuser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/logout")
public class logoutController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //判断session中是否有用户信息
        HttpSession session = req.getSession();
//        如果存在用户信息，则remove删除掉
        if(session.getAttribute("username")!=null){
            session.removeAttribute("username");
        }
//        重定向到用户登录
        resp.sendRedirect("/");
    }
}
